/*
 * acm1268.c
 *
 *  Created on: 4 Apr 2010
 *      Author: xuxu
 */

#include<stdio.h>

int nodefather[1001];

int circle(int node,int f)
{
	int father=node;
	while(nodefather[father]!=-1)
	{
		if(father==f)
		{
			return 1;
		}
		father=nodefather[father];
	}
	return 0;
}

int main()
{
	int f,son;
	int con;
	int bo;
	con=1;
	int countf;
	int i;
	while(scanf("%d%d",&f,&son))
	{
		if(-1==f&&-1==son)
			break;
/*		for(i=0;i<1001;i++)
			nodefather[i]=-1;
			*/
		memset(nodefather,0,sizeof(nodefather));
		bo=0;
		while(f!=0&&son!=0)
		{
			if(nodefather[son]!=0&&nodefather[son]!=-1)
			{
				bo=1;
			}
			nodefather[son]=f;
			if(nodefather[f]==0)
				nodefather[f]=-1;
			if(circle(f,son)!=0)
			{
				bo=1;
			}
			scanf("%d%d",&f,&son);
		}
		countf=0;
		for(i=0;i<1001;i++)
		{
			if(-1==nodefather[i])
				countf++;
			if(countf>1)
			{
				bo=1;
				break;
			}
		}
		if(bo)
			printf("Case %d is not a tree.\n",con);
		else
			printf("Case %d is a tree.\n",con);
		con++;
	}
	return 0;
}
